<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
    <a-form :form="form">
    <a-row style="width: 100%;">
      <a-col :span="24/3">
        <a-form-item label="姓名" :labelCol="labelCol" :wrapperCol="wrapperCol">
             <a-input v-decorator="['name', validatorRules.name]" placeholder="请输入姓名"></a-input>
        </a-form-item>
      </a-col>
      <a-col :span="24/3">
              <a-form-item label="性别" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-select v-decorator="['sex']" placeholder="请选择性别">
                   <a-select-option value="男">男</a-select-option>
                   <a-select-option value="女">女</a-select-option>
                  </a-select>
              </a-form-item>
            </a-col>
      <a-col :span="24/3">
        <a-form-item label="出生日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date v-decorator="['borth']" placeholder="请输入出生日期"  showTime dateFormat="YYYY-MM-DD"></j-date>
        </a-form-item>
      </a-col>
    </a-row>
   <a-row style="width: 100%;">
       <a-col :span="24/3">
        <a-form-item label="联系电话" :labelCol="labelCol" :wrapperCol="wrapperCol">
                 <a-input v-decorator="['phone']" placeholder="请输入联系电话"></a-input>
               </a-form-item>
       </a-col>
       <a-col :span="24/3">
          <a-form-item label="民族" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input v-decorator="['mzcode']" placeholder="请输入民族"></a-input>
                </a-form-item>
       </a-col>
         <a-col :span="24/3">
                <a-form-item label="政治面貌" :labelCol="labelCol" :wrapperCol="wrapperCol">
                         <a-input v-decorator="['zzmm']" placeholder="请输入政治面貌"></a-input>
                       </a-form-item>
              </a-col>
     </a-row>
  <a-row style="width: 100%;">

       <a-col :span="24/3">
          <a-form-item label="身份证号" :labelCol="labelCol" :wrapperCol="wrapperCol">
                   <a-input v-decorator="['sfzh']" placeholder="请输入身份证号"></a-input>
                 </a-form-item>
       </a-col>
        <a-col :span="24/3">
                 <a-form-item label="学历" :labelCol="labelCol" :wrapperCol="wrapperCol">
                          <a-input v-decorator="['xl']" placeholder="请输入学历"></a-input>
                        </a-form-item>
              </a-col>
              <a-col :span="24/3">
                 <a-form-item label="户籍所在地" :labelCol="labelCol" :wrapperCol="wrapperCol">
                          <a-input v-decorator="['hjdz']" placeholder="请输入户籍所在地"></a-input>
                        </a-form-item>
              </a-col>
     </a-row>
     <a-row style="width: 100%;">
        <a-col :span="24/3">
           <a-form-item label="家庭住址" :labelCol="labelCol" :wrapperCol="wrapperCol">
                   <a-input v-decorator="['jtdz']" placeholder="请输入家庭住址"></a-input>
                 </a-form-item>
        </a-col>
        <a-col :span="24/3">
            <a-form-item label="单位" :labelCol="labelCol" :wrapperCol="wrapperCol">
                     <a-input v-decorator="['dwname']" placeholder="请输入单位"></a-input>
                   </a-form-item>
        </a-col>
         <a-col :span="24/3">
                           <a-form-item label="部门" :labelCol="labelCol" :wrapperCol="wrapperCol">
                                   <a-input v-decorator="['bmname']" placeholder="请输入部门"></a-input>
                                 </a-form-item>
                       </a-col>
     </a-row>
     <a-row style="width: 100%;">

               <a-col :span="24/3">
                  <a-form-item label="岗位" :labelCol="labelCol" :wrapperCol="wrapperCol">
                           <a-input v-decorator="['gwname']" placeholder="请输入岗位"></a-input>
                         </a-form-item>
               </a-col>
                <a-col :span="24/3">
                                <a-form-item label="职务或工种" :labelCol="labelCol" :wrapperCol="wrapperCol">
                                        <a-input v-decorator="['zwgz']" placeholder="请输入职务或工种"></a-input>
                                      </a-form-item>
                           </a-col>
                           <a-col :span="24/3">
                             <a-form-item label="职称" :labelCol="labelCol" :wrapperCol="wrapperCol">
                               <a-input v-decorator="['zc']" placeholder="请输入职称"></a-input>
                             </a-form-item>
                           </a-col>
       </a-row>

       <a-row style="width: 100%;">
           <a-col :span="24/3">
               <a-form-item label="入职时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
                 <j-date v-decorator="['rzdate']" placeholder="请输入入职时间"  showTime dateFormat="YYYY-MM-DD"></j-date>
                      </a-form-item>
           </a-col>
           <a-col :span="24/3">
              <a-form-item label="合同类别" :labelCol="labelCol" :wrapperCol="wrapperCol">
                       <a-input v-decorator="['htlb']" placeholder="请输入合同类别"></a-input>
                     </a-form-item>
           </a-col>
            <a-col :span="24/3">
                           <a-form-item label="岗位类别" :labelCol="labelCol" :wrapperCol="wrapperCol">
                                    <a-input v-decorator="['gwlb']" placeholder="请输入岗位类别"></a-input>
                                  </a-form-item>
                       </a-col>
        </a-row>
         <a-row style="width: 100%;">

            <a-col :span="24/3">
                <a-form-item label="岗位运行方式" :labelCol="labelCol" :wrapperCol="wrapperCol">
                        <a-input v-decorator="['gzfs']" placeholder="请输入岗位运行方式"></a-input>
                      </a-form-item>
            </a-col>
              <a-col :span="24/3">
                              <a-form-item label="合同起始日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
                              <j-date v-decorator="['htstdt']" placeholder="请输入合同起始日期""  showTime dateFormat="YYYY-MM-DD"></j-date>
                                    </a-form-item>
                        </a-col>
                        <a-col :span="24/3">
                             <a-form-item label="合同终止日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
                                  <j-date v-decorator="['htenddt']" placeholder="请输入合同终止日期""  showTime dateFormat="YYYY-MM-DD"></j-date>
                                   </a-form-item>
                        </a-col>
        </a-row>

         <a-row style="width: 100%;">
            <a-col :span="24/3">
                  <a-form-item label="合同有效日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
                           <a-input v-decorator="['htyxrq']" placeholder="请输入合同有效日期"></a-input>
                         </a-form-item>
            </a-col>
            <a-col :span="24/3">
                 <a-form-item label="用工来源" :labelCol="labelCol" :wrapperCol="wrapperCol">
                          <a-input v-decorator="['ygly']" placeholder="请输入用工来源"></a-input>
                        </a-form-item>
            </a-col>
             <a-col :span="24/3">
                              <a-form-item label="开资账号" :labelCol="labelCol" :wrapperCol="wrapperCol">
                                       <a-input v-decorator="['kzzh']" placeholder="请输入开资账号"></a-input>
                                     </a-form-item>
                        </a-col>
        </a-row>
         <a-row style="width: 100%;">

            <a-col :span="24/3">
                 <a-form-item label="安全奖" :labelCol="labelCol" :wrapperCol="wrapperCol">
                          <a-input v-decorator="['aqj']" placeholder="请输入安全奖"></a-input>
                        </a-form-item>
            </a-col>
               <a-col :span="24/3">
                               <a-form-item label="月工资" :labelCol="labelCol" :wrapperCol="wrapperCol">
                                       <a-input v-decorator="['ygz']" placeholder="请输入月工资"></a-input>
                                     </a-form-item>
                        </a-col>
                        <a-col :span="24/3">
                            <a-form-item label="奖金系数" :labelCol="labelCol" :wrapperCol="wrapperCol">
                                      <a-input v-decorator="['jjxs']" placeholder="请输入奖金系数"></a-input>
                                    </a-form-item>
                        </a-col>
        </a-row>

          <a-row style="width: 100%;">
             <a-col :span="24/3">
                     <a-form-item label="浮动工资" :labelCol="labelCol" :wrapperCol="wrapperCol">
                             <a-input v-decorator="['fdgz']" placeholder="请输入浮动工资"></a-input>
                           </a-form-item>
             </a-col>
             <a-col :span="24/3">
                  <a-form-item label="代缴" :labelCol="labelCol" :wrapperCol="wrapperCol">
                          <a-input v-decorator="['dj']" placeholder="请输入代缴"></a-input>
                        </a-form-item>
             </a-col>
             <a-col :span="24/3">
                                    <a-form-item label="岗位津贴" :labelCol="labelCol" :wrapperCol="wrapperCol">
                                            <a-input v-decorator="['gwjt']" placeholder="请输入岗位津贴"></a-input>
                                          </a-form-item>
                           </a-col>
         </a-row>
           <a-row style="width: 100%;">

              <a-col :span="24/3">
                   <a-form-item label="是否备案" :labelCol="labelCol" :wrapperCol="wrapperCol">
                           <a-input-number v-decorator="['isba']" placeholder="请输入是否备案" style="width: 100%"/>
                         </a-form-item>
              </a-col>
                <a-col :span="24/3">
                                      <a-form-item label="备注1" :labelCol="labelCol" :wrapperCol="wrapperCol">
                                             <a-input v-decorator="['remark1']" placeholder="请输入备注1"></a-input>
                                           </a-form-item>
                            </a-col>
                            <a-col :span="24/3">
                                  <a-form-item label="备注2" :labelCol="labelCol" :wrapperCol="wrapperCol">
                                          <a-input v-decorator="['remark2']" placeholder="请输入备注2"></a-input>
                                        </a-form-item>
                            </a-col>
          </a-row>

           <a-row style="width: 100%;">
                         <a-col :span="24/3">
                                    <a-form-item label="原因" :labelCol="labelCol" :wrapperCol="wrapperCol">
                                            <a-input v-decorator="['reason']" placeholder="请输入原因"></a-input>
                                          </a-form-item>
                         </a-col>

             </a-row>
      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>
import { httpAction } from '@/api/manage'
import pick from 'lodash.pick'
import { validateDuplicateValue } from '@/utils/util'
import JDate from '@/components/jeecg/JDate'

export default {
  name: 'BjYgruzhiModal',
  components: {
    JDate,
  },
  data() {
    return {
      form: this.$form.createForm(this),
      title: '操作',
      width: 1400,
      visible: false,
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      confirmLoading: false,
      validatorRules: {
        name: { rules: [{ required: true, message: '请输入姓名!' }] },
        sex: { rules: [{ required: true, message: '请选择性别!' }] },
        borth: { rules: [{ required: true, message: '请输入出生日期!' }] },
        mzcode: { rules: [{ required: true, message: '请输入民族!' }] },
        sfzh: { rules: [{ required: true, message: '请输入身份证号!' }] },
        labelCol: { rules: [{ required: true, message: '请输入户籍所在地!' }] },
      },
      url: {
        add: '/bj/bjYgruzhi/add',
        edit: '/bj/bjYgruzhi/edit',
      },
    }
  },
  created() {},
  methods: {
    add() {
      this.edit({})
    },
    edit(record) {
      this.form.resetFields()
      this.model = Object.assign({}, record)
      this.visible = true
      this.$nextTick(() => {
        this.form.setFieldsValue(
          pick(
            this.model,
            'name',
            'sex',
            'borth',
            'phone',
            'mzcode',
            'zzmm',
            'sfzh',
            'xl',
            'hjdz',
            'jtdz',
            'dwname',
            'bmname',
            'gwname',
            'zwgz',
            'zc',
            'rzdate',
            'htlb',
            'gwlb',
            'gzfs',
            'htstdt',
            'htenddt',
            'htyxrq',
            'ygly',
            'kzzh',
            'aqj',
            'ygz',
            'jjxs',
            'fdgz',
            'dj',
            'gwjt',
            'remark1',
            'remark2',
            'isba',
            'reason',
            'createBy',
            'createTime',
            'updateBy',
            'updateTime'
          )
        )
      })
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    handleOk() {
      const that = this
      // 触发表单验证
      this.form.validateFields((err, values) => {
        if (!err) {
          that.confirmLoading = true
          let httpurl = ''
          let method = ''
          if (!this.model.id) {
            httpurl += this.url.add
            method = 'post'
          } else {
            httpurl += this.url.edit
            method = 'put'
          }
          let formData = Object.assign(this.model, values)
          console.log('表单提交数据', formData)
          httpAction(httpurl, formData, method)
            .then((res) => {
              if (res.success) {
                that.$message.success(res.message)
                that.$emit('ok')
              } else {
                that.$message.warning(res.message)
              }
            })
            .finally(() => {
              that.confirmLoading = false
              that.close()
            })
        }
      })
    },
    handleCancel() {
      this.close()
    },
    popupCallback(row) {
      this.form.setFieldsValue(
        pick(
          row,
          'name',
          'sex',
          'borth',
          'phone',
          'mzcode',
          'zzmm',
          'sfzh',
          'xl',
          'hjdz',
          'jtdz',
          'dwname',
          'bmname',
          'gwname',
          'zwgz',
          'zc',
          'rzdate',
          'htlb',
          'gwlb',
          'gzfs',
          'htstdt',
          'htenddt',
          'htyxrq',
          'ygly',
          'kzzh',
          'aqj',
          'ygz',
          'jjxs',
          'fdgz',
          'dj',
          'gwjt',
          'remark1',
          'remark2',
          'isba',
          'reason',
          'createBy',
          'createTime',
          'updateBy',
          'updateTime'
        )
      )
    },
  },
}
</script>